//判断是否的登录
function goodsDetail_login() {
    var user = document.getElementById("top1_login").innerText;
    var top1 = document.getElementById("top1");
    var container_top = document.getElementById("container_top");
    if (user.trim().length == 0){
        document.getElementById("top1_login").innerText = "登录";
        document.getElementById("top2_gwc").innerText = "0";
        top1.style.width = "140px";
        container_top.style.width = "240px";
        container_top.style.marginLeft = "288px";
    }else if (user.trim().length != 0 && user != "登录"){
        document.getElementById("top1_login").setAttribute("href","#");
        top1.style.width = "195px";
        container_top.style.width = "300px";
        container_top.style.marginLeft = "234px";
    }
}

function orderDataList() {
    $(function () {
        $.ajax({
            url: "orderDetailServlet?orderList_ordernumber="+document.getElementById("order_number").innerText,
            type: "get",
            dataType: "json",
            success: function (res) {
                for (var i = 0; i < res.length; i++) {
                    document.getElementById("order_time").innerText = res[i].orderSubmissionTime;
                    document.getElementById("recipients").innerText = res[i].consigneeName;
                    document.getElementById("phone").innerText = res[i].phone;
                    document.getElementById("Delivery_Address").innerText = res[i].receiverAddress;
                    document.getElementById("total_prices").innerText = res[i].prices;
                }
            },
            error: function (res) {
                alert("所有购物车获取失败！")
            }
        });
    });
}

function orderDatamerchandise () {
    $(function () {
        $.ajax({
            url: "orderDataMerchandiseServlet?orderList_ordernumber="+document.getElementById("order_number").innerText,
            type: "get",
            dataType: "json",
            success: function (res) {
                var orderDetailAdd = $("#orderDetailAdd");
                orderDetailAdd.empty();
                for (var i = 0; i < res.length; i++) {
                    var tr = document.createElement("tr");
                    tr.style.fontSize = "13px";

                    var td_1 = document.createElement("td");
                    td_1.innerText = i+1;

                    var td_2 = document.createElement("td");
                    var img = document.createElement("img");
                    img.setAttribute("src",res[i].consignee_picture);
                    img.setAttribute("width","50px");
                    img.setAttribute("height","50px");
                    td_2.appendChild(img);

                    var td_3 = document.createElement("td");
                    td_3.innerText = res[i].consignee_name;

                    var td_4 = document.createElement("td");
                    td_4.innerText = res[i].consignee_price;

                    var td_5 = document.createElement("td");
                    td_5.innerText = res[i].quantity;

                    var td_6 = document.createElement("td");
                    td_6.innerText = res[i].total_prices;

                    tr.appendChild(td_1);
                    tr.appendChild(td_2);
                    tr.appendChild(td_3);
                    tr.appendChild(td_4);
                    tr.appendChild(td_5);
                    tr.appendChild(td_6);
                    orderDetailAdd.append(tr);
                }
            },
            error: function (res) {
                alert("所有购物车获取失败！")
            }
        });
    });
}

function jump_online_payment() {
    window.location.href = "/MyXiaomiShop/orderDetail_payWeixin?order_number="+document.getElementById("order_number").innerText;
}

function Return_order() {
    window.location.href = "/MyXiaomiShop/orderList.jsp";
}

function orderDatails_state() {
    $(function () {
        $.ajax({
            url: "orderList_orderDatail_stateServlet?orderList_order_number=" + document.getElementById("order_number").innerText,
            type: "get",
            dataType: "json",
            success: function (res) {
                if (res != "未付款") {
                    $("#orderDatail_online_payment").attr("disabled",true);
                }else {
                    $("#orderDatail_online_payment").attr("disabled",false);
                }
            },
            error: function (res) {
                alert("所有购物车获取失败！")
            }
        });
    });
}